package publisherSubscriber.examples;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import publisherSubscriber.Factory;
import publisherSubscriber.Publisher;

public class PublisherApp {
	
	public static void main(String[] args) {
		try {
			if(args.length != 4){
				System.out.println("Usage: PublisherApp host port topicName subscriberName");
				System.exit(1);
			}
			
			Factory factory = new Factory(args[0],args[1]);
			Publisher publisher = factory.createPublisher(args[2], args[3]);
			System.out.println(publisher.getPublisherName()+" publisher connected.");			
			
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			
			String input;
			do{
				System.out.println("Say something:");
				input = br.readLine();
				publisher.write(input);
				
			}while(!input.equals("exit"));
			
		} catch (Exception e) {			
			e.printStackTrace();
		}
	}
	
	
}
